package com.niit.bean;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class OtherTopOneBean implements WritableComparable<OtherTopOneBean> {
    private String city; // 城市
    private String school; // 学校
    private long studentCount; // 异地学生人数

    public OtherTopOneBean() {
    }

    public OtherTopOneBean(String city, String school, long studentCount) {
        this.city = city;
        this.school = school;
        this.studentCount = studentCount;
    }

    public void set(String city, String school, long studentCount) {
        this.city = city;
        this.school = school;
        this.studentCount = studentCount;
    }

    public String getcity() {
        return city;
    }

    public void setcity(String city) {
        this.city = city;
    }

    public String getschool() {
        return school;
    }

    public void setschool(String school) {
        this.school = school;
    }

    public long getstudentCount() {
        return studentCount;
    }

    public void setstudentCount(long studentCount) {
        this.studentCount = studentCount;
    }

    @Override
    public String toString() {
        return "城市：" + city + ", 学校：" + school + ", 异地学生人数：" + studentCount;
    }

    @Override
    public int compareTo(OtherTopOneBean o) {
        int result ;

        int i = city.compareTo(o.getcity());

        if ( i > 0) {
            result =1;
        } else if (i <0 ) {
            result = -1;
        } else {
            // 确诊病例数倒序排序
            result = studentCount > o.getstudentCount() ? -1 : (studentCount < o.getstudentCount()? 1:0);
        }

        return result;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(city);
        dataOutput.writeUTF(school);
        dataOutput.writeLong(studentCount);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.city = dataInput.readUTF();
        this.school = dataInput.readUTF();
        this.studentCount = dataInput.readLong();
    }
}